function simulateClickSelect(element) {
    const event = new MouseEvent('click', {
        bubbles: true,
        cancelable: true,
        view: window
    });
    if(element!=null) element.dispatchEvent(event);
}

function setvalue(name,value) {
    return new Promise((resolve) => {
        // 找到所有包含 品牌 的 span.item-title-text 元素
        itemTitleTexts = document.querySelectorAll('.edit-label,.edit-title');
        itemTitleTexts.forEach(itemTitleText => {
            if (itemTitleText.innerText.includes(name)) {
                // 找到其父级 div.attribute-select-item 下的 .shopee-selector__inner 点击
                editRowRightMedium = itemTitleText.closest('.edit-row').querySelector('input[type=text],textarea');
                if (editRowRightMedium) {
                    editRowRightMedium.value=value;
                    resolve();
                }
                editRowRightMedium = itemTitleText.closest('.edit-row').querySelector('.shopee-selector__inner,.shopee-selector--tags,.scroll-selector-content');
                if (editRowRightMedium) {
                    editRowRightMedium.click();
                    setTimeout(function(){
                        targetElements=document.querySelectorAll(".shopee-select__menu");
                        targetElements.forEach(targetElement => {
                            if (targetElement.style.display == '' &&targetElement.style.visibility == '') {
                                options=targetElement.querySelectorAll(".shopee-option");
                                options.forEach(option => {
                                    let text = option.textContent;
                                    if (text.includes(value)) {
                                        option.click();
                                        resolve();
                                    }
                                });
                            }
                        });
                    },1000)
                }else{
                    resolve();
                }
            }
        });

    });
}

